<template>
  <div class="my">
    <!-- 顶部 -->
    <div class="top">
      <!-- 头像和昵称 -->
      <div class="box1">
        <!-- 昵称 -->
        <div class="name">
          <div>{{ user.nickname }}</div>
          <span>{{ user.intro }}</span>
        </div>
        <!-- 头像 -->
        <div class="avatar" @click="goInfo">
          <img v-if="user.avatar === null" src="@/assets/avatar.jpeg" />
          <img v-else :src="`${baseURL + user.avatar} `" />
        </div>
      </div>
      <!-- 数据 -->
      <div class="box2">
        <div class="items">
          <div class="item">
            <div>{{ user.submitNum }}</div>
            <span>累计答题</span>
          </div>
          <div class="item">
            <div>{{ user.collectQuestions.length }}</div>
            <span>收藏题目</span>
          </div>
          <div class="item">
            <div>{{ user.errorQuestions.length }}</div>
            <span>我的错题</span>
          </div>
          <div class="item">
            <div v-if="user.submitNum !== 0">
              {{
                Math.round(
                  ((user.submitNum - user.errorNum) / user.submitNum) * 100
                )
              }}<span class="percent">%</span>
            </div>
            <div v-else>0<span class="percent">%</span></div>
            <span>正确率</span>
          </div>
        </div>
      </div>
      <div class="box3">
        <van-cell
          class="mycell"
          title="我的岗位"
          icon="location-o"
          is-link
          :value="user.position"
          @click="goEdit"
        >
          <template #icon>
            <i class="iconfont iconicon_mine_gangwei myicon"></i>
          </template>
        </van-cell>
      </div>
    </div>
    <div class="dataBox">
      <div class="face">
        <h3>面经数据</h3>
        <div class="items">
          <div class="item">
            <div class="topBox">
              昨日阅读<span>+{{ user.shareData.read.yesterday }}</span>
            </div>
            <div class="centerBox">{{ user.shareData.read.total }}</div>
            <div class="bottomBox">阅读总数</div>
          </div>
          <div class="item">
            <div class="topBox">
              昨日获赞<span>+{{ user.shareData.star.yesterday }}</span>
            </div>
            <div class="centerBox">{{ user.shareData.star.total }}</div>
            <div class="bottomBox">获赞总数</div>
          </div>
          <div class="item">
            <div class="topBox">
              昨日评论<span>+{{ user.shareData.comment.yesterday }}</span>
            </div>
            <div class="centerBox">{{ user.shareData.comment.total }}</div>
            <div class="bottomBox">评论总数</div>
          </div>
        </div>
      </div>
      <div class="other">
        <van-cell
          class="mycell"
          title="我的面经分享"
          icon="location-o"
          is-link
          value="21"
        >
          <template #icon>
            <i class="iconfont iconicon_mine_mianjing myicon"></i>
          </template>
        </van-cell>
        <van-cell
          class="mycell"
          title="我的消息"
          icon="location-o"
          is-link
          value="98"
        >
          <template #icon>
            <i class="iconfont iconicon_mine_xiaoxi myicon"></i>
          </template>
        </van-cell>
        <van-cell
          class="mycell"
          title="收藏的题库"
          icon="location-o"
          is-link
          value="32"
        >
          <template #icon>
            <i class="iconfont iconicon_mine_tikushoucang myicon"></i>
          </template>
        </van-cell>
        <van-cell
          class="mycell"
          title="收藏的企业"
          icon="location-o"
          is-link
          value="312"
        >
          <template #icon>
            <i class="iconfont iconicon_mine_qiyeshoucang myicon"></i>
          </template>
        </van-cell>
        <van-cell
          class="mycell"
          title="我的错题"
          icon="location-o"
          is-link
          value="2134"
        >
          <template #icon>
            <i class="iconfont iconicon_mine_cuoti myicon"></i>
          </template>
        </van-cell>
        <van-cell
          class="mycell"
          title="收藏的面试经验"
          icon="location-o"
          is-link
          value="123"
        >
          <template #icon>
            <i class="iconfont iconbtn_shoucang_sel myicon"></i>
          </template>
        </van-cell>
      </div>
    </div>
  </div>
</template>
<script>
// 导入辅助函数
import { mapState } from 'vuex'
export default {
  name: 'my',
  data () {
    return {
      // user: undefined
      baseURL: process.env.VUE_APP_BaseURL
    }
  },
  methods: {
    goEdit () {
      this.$router.push('/editInfo?prop=position')
    },
    goInfo () {
      this.$router.push('/info')
    }
  },
  created () {
    // this.user = this.$store.state.user
    // console.log(this.user)
  },
  computed: {
    ...mapState(['user'])
  }
}
</script>

<style lang="less" scoped>
.my {
  font-size: 12px;
  // height: 100vh;
  padding-bottom: 70px;
  background-color: #f7f4f5;
  .top {
    box-sizing: border-box;
    padding: 32px 15px 0;
    background: linear-gradient(45deg, #ce0031, #b8002c);
    height: 216px;
    .box1 {
      display: flex;
      justify-content: space-between;
      align-items: center;
      color: #fff;
      font-family: PingFangSC, PingFangSC-Semibold;
      font-size: 12px;
      .name {
        div {
          // font-weight: 600;
          font-size: 21px;
          line-height: 30px;
        }
        span {
          line-height: 23px;
          opacity: 0.7;
        }
      }
      .avatar {
        margin-right: 22px;
        img {
          width: 50px;
          height: 50px;
          border-radius: 50%;
          border: 3px solid rgba(255, 255, 255, 0.38);
        }
      }
    }
    .box2 {
      margin-top: 30px;
      color: #fff;
      .items {
        display: flex;
        justify-content: center;
        // align-items: center;
        .item {
          flex: 1;
          text-align: center;
          div {
            font-size: 21px;
            font-weight: 600;
            .percent {
              opacity: 1;
            }
          }
          span {
            margin-top: 10px;
            font-size: 12px;
            opacity: 0.7;
          }
        }
      }
    }
    .box3 {
      border-radius: 6px;
      overflow: hidden;
      margin-top: 16px;
      .mycell {
        display: flex;
        align-items: center;
        height: 55px;
        .myicon {
          font-size: 20px;
          margin-right: 10px;
        }
      }
    }
  }
  .dataBox {
    padding: 0 15px;
    .face {
      margin-top: 27px;
      padding: 20px 15px 16px;
      background-color: #fff;
      border-radius: 6px;
      h3 {
        margin: 0;
        font-size: 14px;
        font-family: PingFangSC, PingFangSC-Semibold;
      }
      .items {
        display: flex;
        .item {
          flex: 1;
          text-align: center;
          .topBox {
            margin-top: 18px;
            font-size: 10px;
            color: #b4b4bd;
            span {
              color: #00b8d4;
            }
          }
          .centerBox {
            margin: 10px 0 5px;
            font-size: 21px;
            font-weight: bold;
            color: #181a39;
          }
          .bottomBox {
            color: #545671;
          }
        }
      }
    }
    .other {
      margin-top: 10px;
      overflow: hidden;
      border-radius: 6px;
      background-color: #fff;
      .myicon {
        margin-right: 10px;
      }
    }
  }
}
</style>
